// pages/login/login.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    islogin: false,
    avatarurl: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    console.log(this.data.data)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  onPhoneEvent: function (event) {
    if (event.detail.value) {
      var value = event.detail.value;
      var that = this;
      that.setData({
        phone: value
      })
    }
  },
  onPasswordEvent: function (event) {
    if (event.detail.value) {
      var value = event.detail.value;
      var that = this;
      that.setData({
        password: value
      })
    }
  },
  onLoginEvent:function(){
    var that=this;
    var phone = that.data.phone;
    var password = that.data.password;
    wx.request({
      url: 'http://neteasemusic.leanapp.cn/login/cellphone',
      data:{
        phone: phone,
        password: password
      },
      success: function (res) {
        if (res.data.account){
          var uid = res.data.account.id
        } else{
          uid = 59180335
        }
        that.setData({
          uid: uid
        })
        wx.request({
          url: 'http://neteasemusic.leanapp.cn/user/detail',
          data:{
            uid : uid
          },
          success: function (res) {
            that.setData({
              data: res.data,
              islogin:true,
              avatarurl: res.data.profile.avatarUrl
            })
            getApp().globalData.uid = that.data.uid
            wx.request({
              url: 'http://neteasemusic.leanapp.cn/personal_fm',
              success: function (res) {
                console.log("sss")
                console.log(res)
                console.log("sss")
              }
            })
          }
        })
      }
    })
  }
})